﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace Project.module
{
    public partial class frmAddnewmon : Form
    {
        private LoaimonDTO Loaimon =null;
        public class ComboboxItem
        {
            public string Text { get; set; }
            public int Value { get; set; }

            public override string ToString()
            {
                return Text;
            }
        }
        public frmAddnewmon()
        {
            InitializeComponent();
        }

        private void frmAddnewmon_Load(object sender, EventArgs e)
        {
            Loaimon = (LoaimonDTO)this.Tag;
            List<LoaimonDTO> lst = LoaiMonBUS.Listloaimon();
            if (lst != null)
            {
                foreach (LoaimonDTO loai in lst)
                {
                    ComboboxItem itm = new ComboboxItem();
                    itm.Text = loai.Tenloai;
                    itm.Value = loai.Maloai;
                    cbLoaimon.Items.Add(itm);
                    
                }
                cbLoaimon.SelectedText = Loaimon.Tenloai;

            }
            List<DonViTinhDTO> lstdv = DonViTinhBUS.Danhsach();
            if (lst != null)
            {
                foreach (DonViTinhDTO dv in lstdv)
                {
                    ComboboxItem itmdv = new ComboboxItem();
                    itmdv.Text = dv.Tendv;
                    itmdv.Value = dv.Madv;
                    cbDVT.Items.Add(itmdv);
                }
                cbDVT.SelectedIndex = 0;
                
            }
            

        }

        private void bntThem_Click(object sender, EventArgs e)
        {
            MonAnDTO mon = new MonAnDTO();
            mon.Madv = 1;
            mon.Maloai = Loaimon.Maloai;
            mon.Tenmon = txtTenmon.Text;
            mon.Dongia = float.Parse(txtDongia.Text);
            if (MonAnBUS.Themmon(mon))
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("Không thành công");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
